package com.gec.init;

import com.gec.dao.UserInfoDao;
import com.gec.domain.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

//@Component
public class JdbcInit {

    //@Autowired
    private UserInfoDao userInfoDao;

    //通过该注解,在bean装配完成后执行标注的方法,初始化数据库信息
    //@PostConstruct
    public void init() {

        PasswordEncoder encoder = new BCryptPasswordEncoder();

        UserInfo user = new UserInfo();
        user.setUsername("zhangsan");
        user.setPassword(encoder.encode("123"));
        user.setRole("normal");
        userInfoDao.save(user);

        user = new UserInfo();

        user.setUsername("lisi");
        user.setPassword(encoder.encode("123"));
        user.setRole("admin");
        userInfoDao.save(user);
    }
}
